package com.team.hiring.common.entity;

import java.util.List;

/**
 * 分页查询返回的实体
 * @author Administrator
 *
 */
public class PageModel<T> {

	/**

	 * 数据

	 */
	private List<T> list;

	/**

	 * 总共有多少条数据

	 */
	private int totalRecords;

	/**

	 * 当前这批数据是在第几页

	 */
	private int pageNo;

	/**

	 * 每页显示了多少条数据

	 */
	private int pageSize;

	public PageModel() {
		super();
	}

	public PageModel(List<T> list, int totalRecords, int pageNo, int pageSize) {
		super();
		this.list = list;
		this.totalRecords = totalRecords;
		this.pageNo = pageNo;
		this.pageSize = pageSize;
	}

	/**

	 * 计算出总共有多少页

	 * 

	 * @return

	 */
	public int getTotalPage() {
		return (int) Math.ceil((double) totalRecords / pageSize);
	}

	/**

	 * 首页

	 * 

	 * @return

	 */
	public int getFirst() {
		return 1;
	}

	/**

	 * 尾页

	 * 

	 * @return

	 */
	public int getLast() {
		return getTotalPage();
	}

	/**

	 * 上一页

	 * 

	 * @return

	 */
	public int getPre() {
		if (pageNo == 1) {
			return 1;
		}
		return pageNo - 1;
	}

	/**

	 * 下一页

	 * 

	 * @return

	 */
	public int getNext() {
		if (pageNo == getTotalPage()) {
			return getTotalPage();
		}
		return pageNo + 1;
	}

	public List<T> getList() {
		return list;
	}

	public void setList(List<T> list) {
		this.list = list;
	}

	public int getTotalRecords() {
		return totalRecords;
	}

	public void setTotalRecords(int totalRecords) {
		this.totalRecords = totalRecords;
	}

	public int getPageNo() {
		return pageNo;
	}

	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
}
